home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig15_11.jar / Ch15 / Fig15_11 / fig15_11.cpp next >
C/C++ Source or Header  |  1997-11-10  |  949b  |  42 lines

  1. // Fig. 15.11: fig15_11.cpp
  2. // Driver to test the template Stack class
  3. #include <iostream.h>
  4. #include "stack_c.h"
  5.  
  6. int main()
  7. {
  8.    Stack< int > intStack;
  9.    int popInteger;
  10.    cout << "processing an integer Stack" << endl;
  11.  
  12.    for ( int i = 0; i < 4; i++ ) {
  13.       intStack.push( i );
  14.       intStack.printStack();
  15.    }
  16.  
  17.    while ( !intStack.isStackEmpty() ) {
  18.       intStack.pop( popInteger );
  19.       cout << popInteger << " popped from stack" << endl;
  20.       intStack.printStack();
  21.    }
  22.  
  23.    Stack< double > doubleStack;
  24.    double val = 1.1, popdouble;
  25.  
  26.    cout << "processing a double Stack" << endl;
  27.  
  28.    for ( i = 0; i < 4; i++ ) {
  29.       doubleStack.push( val );
  30.       doubleStack.printStack();
  31.       val += 1.1;
  32.    }
  33.  
  34.    while ( !doubleStack.isStackEmpty() ) {
  35.       doubleStack.pop( popdouble );
  36.       cout << popdouble << " popped from stack" << endl;
  37.       doubleStack.printStack();
  38.    }
  39.  
  40.    return 0;
  41. }
  42.